<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
</head>
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-lg-offset3" layui-col-lg6>
            <div class="layui-form layuimini-form">
                <form class="layui-form" action="" lay-filter="userForm">
                    <div class="layui-form-item">
                        <label class="layui-form-label">校区：</label>
                        <div class="layui-input-inline">
                            <select name="campus">
                                <option value="" selected="">选择校区</option>
                                <option value="东部校区" style="descent-override:false ;">东部校区</option>
                                <option value="西部校区">西部校区</option>
                            </select>
                        </div>
                    </div>
                    <input type="hidden" name="id" value="" class="layui-input">
            

                    <div class="layui-form-item">
                        <label class="layui-form-label">位置：</label>
                        <div class="layui-input-inline">
                            <select name="position">
                                <option value="" selected="">请选择校区</option>
                                <option value="明德楼">明德楼</option>
                                <option value="图书馆">图书馆</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">部门/房号：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="department" required lay-verify="required" placeholder="如：302或学生处"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">保修人姓名：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="applicant" required lay-verify="required" placeholder="如实填写"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">电话：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="phone" required lay-verify="required" placeholder="请输入电话号码"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">报修类型</label>
                        <div class="layui-input-inline">
                            <select name="typeWork">
                                <option value="木工">木工</option>
                                <option value="水电" selected="">水电</option>
                                <option value="粉刷">粉刷</option>
                                <option value="空调">空调</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">报修(损坏)项目：</label>
                        <div class="layui-input-block">
                            <input type="text" name="details" required lay-verify="required" placeholder="写明需要维修的物品"
                                   autocomplete="off" class="layui-input">
                        </div>

                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">备注：</label>
                        <div class="layui-input-block">
                            <input type="text" name="remarks" required lay-verify="required" placeholder="如什么时候可以去维修等"
                                   autocomplete="off" class="layui-input">
                        </div>

                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">上传时间：</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="startTime" id="time" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" readonly>
                        </div>
                        <!-- id等于的time只要和下面的名字对应就行 -->
                        <script>
                            Date.prototype.format = function (fmt) {
                                var o = {
                                    "y+": this.getFullYear, //年
                                    "M+": this.getMonth() + 1, //月份
                                    "d+": this.getDate(), //日
                                };
                                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                                for (var k in o)
                                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                                return fmt;
                            }
                            document.getElementById('time').value = (new Date()).format('yyyy-MM-dd');
                        </script>			
                    </div>
                    <!-- <div class="layui-form-item">
                        <label class="layui-form-label">applicationTime：</label>
                        <input type="hidden" name="remarks" id="pic">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" id="durl">
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>

                            <div class="layui-upload-list">
                                <img style="width: 100px" class="layui-upload-img" id="demo1">
                                <p id="demoText"></p>
                            </div>

                            <div style="width: 95px;">
                                <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">
                                    <div class="layui-progress-bar" lay-percent=""></div>
                                </div>
                            </div>

                        </div>

                    </div> -->

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>



<script>
    //Demo
    layui.use(['form','element','upload'], function () {
        var form = layui.form
            , $ = layui.jquery
            ,element = layui.element
            ,upload = layui.upload
            , laydate = layui.laydate;

        //日期   渲染上面 id 为 date 的 标签
        laydate.render({
            elem: '#date'
        });

        // 执行实例
        // var uploadInst = upload.render({
        //     elem: '#durl' //绑定元素
        //     ,url: 'http://localhost:8080/repair/upload' //上传接口
        //     ,field: "file"
        //     ,before: function(obj){
        //         //预读本地文件示例，不支持ie8
        //         obj.preview(function(index, file, result){
        //             $('#demo1').attr('src', result); //图片链接（base64）
        //         });

        //         element.progress('demo', '0%'); //进度条复位
        //         layer.msg('上传中', {icon: 16, time: 0});
        //     }
        //     ,done: function(res){
        //         debugger
        //         //上传完毕回调
        //         if(res.code==200){
        //             $("#demo1").attr("src",res.data.url);
        //             $("#pic").val(res.data.url);  //把图片地址 写到隐藏域 上传的时候 传到后台
        //         }


        //         $('#demoText').html(''); //置空上传失败的状态

        //     }
        //     ,error: function(){
        //         //请求异常回调
        //         //演示失败状态，并实现重传
        //         var demoText = $('#demoText');
        //         demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
        //         demoText.find('.demo-reload').on('click', function(){
        //             uploadInst.upload();
        //         });

        //     }
        //     //进度条
        //     ,progress: function(n, elem, e){
        //         element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
        //         if(n == 100){
        //             layer.msg('上传完毕', {icon: 1});
        //         }
        //     }  
        // });


        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            // data = data.field;
            //     console.log(data);
            //     if (data.campus == '') {
            //         layer.msg('请选择校区');
            //         return false;
            //     }
            //     if (data.position == '') {
            //         layer.msg('请选择所在位置');
            //         return false;
            //     }
            $.ajax({
                "url":"http://localhost:8080/repair/addWorkOrder",
               // "headers":{"token":token},
                "data": data.field,
                // result 参数 表式后台响应的数据
                "success":function(result){
                    if(result.code == 200){

                        // 关闭 弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.msg("添加成功");
                        parent.layer.close(iframeIndex);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });

            return false;
        });
    });
</script>


</body>

</html>